#include <bits/stdc++.h>

using namespace std;

int n,s;
int main()
{
    priority_queue< int,vector<int>,greater<int> > q;
    cin>>n;
    for(int i = 1;i<=n;i++){
        int a;
        cin>>a;
        q.push(a);
    }
    for(int i=1;i<n;i++){
        int a;
        a=q.top();
        q.pop();
        a+=q.top();
        q.pop();
        s += a;
        q.push(a);
    }
    cout<<s;
    return 0;
}
